<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
use lib\UserCrypt;
class Caseings extends Base{
	//在线提案
	public function caseIn()
	{
		if(!empty(input("param.token"))){
            $token=input("param.token");
        }else{
            return json(['code' => 501, 'msg' => '令牌呢？']);
        }
		if(!empty(input("param.company"))){
			$data['company']=input("param.company");
		}else{
			return json(['code' => 502, 'msg' => '公司/商户']);
		}
        if(!empty(input("param.name"))){
            $data['name']=input("param.name");
        }else{
            return json(['code' => 503, 'msg' => '联系人']);
        }
        if(!empty(input("param.phone"))){
            $data['phone']=input("param.phone");
        }else{
            return json(['code' => 504, 'msg' => '联系人电话']);
        }
        if(!empty(input("param.product_name"))){
            $data['product_name']=input("param.product_name");
        }else{
            return json(['code' => 505, 'msg' => '产品名称']);
        }
        if(!empty(input("param.model"))){
            $data['model']=input("param.model");
        }else{
            return json(['code' => 506, 'msg' => '型号']);
        }
        if(!empty(input("param.spec"))){
            $data['spec']=input("param.spec");
        }else{
            return json(['code' => 507, 'msg' => '规格']);
        }
        if(!empty(input("param.num"))){
            $data['num']=input("param.num");
        }else{
            return json(['code' => 508, 'msg' => '数量']);
        }
        if(!empty(input("param.units"))){
            $data['units']=input("param.units");
        }else{
            return json(['code' => 509, 'msg' => '计量单位']);
        }
        if(!empty(input("param.message"))){
            $data['message']=input("param.message");
        }
        $uid=UserCrypt::do_mdecrypt($token);
        $isCase=Db::name('caseings')->where('user_id',$uid)->where('time','>',time()
            -60)->find();
        if($isCase){
            return json(['code' => 510, 'msg' => '短时间内不要重复提交！']);
        }else{
            $data['user_id']=$uid;
            $data['state']=1;
            $data['time']=time();
            $data['uptime']=time();
            $res=Db::name('caseings')->insert($data);
            if ($res) {
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
	}
}